#include<iostream>
using namespace std;
int main()
{
	int n;
	int m, s;
	cin >> n >> m >> s;
	char arr[100][20];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	m -= 2;
	int count = 0;
	while (count < n) {
		for (int i = 0; i < s; i++) {
			m = (++m) % n;
			if (arr[m][18] == '1') {
				i--;
			}
		}
		cout << arr[m] << endl;
		arr[m][18] = '1';
		count++;
	}
	return 0;
}